<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AD Update</title>
</head>

<body>

<cfinclude template="/code_lib/SCF_Employee.cfm">
<cfinclude template="/code_lib/SCF_HR.cfm">

<cffunction name="func_GetPosDisplay" returntype="string">
	<cfargument name="pstrPos" type="string" required="yes">

	<cfset var FUNC = StructNew() />
	<cfset FUNC.retval = trim(pstrPos) />
	
	<!--- instead of making this one long unreadable line, i've chosen to display each replace on it's own line --->
	<cfif FUNC.retval NEQ 'YMI Participant'>
		<cfset FUNC.retval = replace(FUNC.retval, ' IPA', '')>
	</cfif>
	<cfset FUNC.retval = replace(FUNC.retval, ' MOA', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' HBS', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' - Takotna', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' - Nickolai', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' FMC', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' BHC', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' Peds', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' COS', '')>
	<!---cfset FUNC.retval = replace(FUNC.retval, ' CIO', '')---> <!--- commented per Chris' request, 3/9/2009--->
	<cfset FUNC.retval = replace(FUNC.retval, ' QI', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' QA', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' IV', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' III', '')>
	<cfset FUNC.retval = replace(FUNC.retval, ' II', '')>
	<cfif Find(' Information', FUNC.retval) EQ 0 AND Find(' Infect', FUNC.retval) EQ 0 AND Find(' Intern', FUNC.retval) EQ 0 AND Find(' Improv', FUNC.retval) EQ 0>
		<cfset FUNC.retval = replace(FUNC.retval, ' I', '')>
	</cfif>
	<cfset FUNC.retval = replace(FUNC.retval, ' Technician I', ' Technician')>
	<cfset FUNC.retval = replace(FUNC.retval, ' Intern I', ' Intern')>
	<cfset FUNC.retval = replace(FUNC.retval, ' Director I', ' Director')>
	<cfset FUNC.retval = replace(FUNC.retval, ' Intern I', ' Intern')>
	<cfset FUNC.retval = replace(FUNC.retval, ' Supervisor I', ' Supervisor')>
	<cfset FUNC.retval = replace(FUNC.retval, ' TPT', '')>
	<cfif Find('thru 12', FUNC.retval) EQ 0>
		<cfset FUNC.retval = replace(FUNC.retval, ' 1', '')>
	</cfif>

	<cfreturn FUNC.retval />
	
</cffunction>

<cfset arrEmp = SCF_Employee_Get_AllEmployees(0,0)>

<cfobject type="dotnet" name="objMod" class="ADTools.Modify" assembly ="C:\Program Files\Southcentral Foundation\ADTools\ADTools.dll">      
<cfset lngResult = objMod.ConnectToLDAP("10.100.1.101")>
<cfset intUpdated = 0>
<cfset intError = 0>
<cfset intSkipped = 0>

<!---cfoutput>
	<table>
	<cfloop from="1" to="10" index="intX">
	<!---cfloop from="1" to="#ArrayLen(arrEmp)#" index="intX"--->
		<cfset arrPos = SCF_HR_GetJobPositions(arrEmp[intX].RosettaID)>
		<cfif arrPos[1].Title NEQ '[Position Not Found]'>
		<TR>
			<TD>#arrEmp[intX].RosettaID#</TD>
			<TD>&nbsp;&nbsp;&nbsp;</TD>
			<TD>#arrPos[1].Title#</TD>
			<TD>&nbsp;&nbsp;&nbsp;</TD>
			<TD>#func_GetPosDisplay(arrPos[1].Title)#</TD> 
			<TD>&nbsp;&nbsp;&nbsp;</TD>
			<TD>#arrPos[1].Department.DisplayName#</TD>
		</TR>
		</cfif>
	</cfloop>
	</table>
</cfoutput--->





<cfmail to="bfrick@scf.cc" from="ADUpdate@scf.cc" subject="AD Mass Update" type="html">
<!---cfmail to="SCFAppNotifyAdmin@scf.cc" from="ADUpdate@scf.cc" subject="AD Mass Update" type="html"--->

	<!---cfloop from="1" to="100" index="intX"--->
	<cfloop from="1" to="#ArrayLen(arrEmp)#" index="intX">
	
		<cfset strUserID = arrEmp[intX].Login>
		<cfset arrPos = SCF_HR_GetJobPositions(arrEmp[intX].RosettaID)>
		
		<cfif arrPos[1].Title NEQ '[Position Not Found]' and left(strUserID, 4) NEQ "ANMC">		
			<cfset strError="">	
			<cfset strTitle = #Trim(arrPos[1].Title)#>
			<cfset strDesc = #Trim(func_GetPosDisplay(arrPos[1].Title))#>
			<cfset strDept = #Trim(arrPos[1].Department.DisplayName)#>
		
			<!---cfset lngResult = objMod.ModifyUser("#strUserID#", "description", JavaCast("string", "#strDesc# (#strTitle#)"))--->  
			<!---cfif lngResult EQ 0>
				<cfset lngResult = objMod.ModifyUser("#strUserID#", "title", JavaCast("string", "#strDesc#"))>
				<cfif lngResult EQ 0>
					<cfset lngResult = objMod.ModifyUser("#strUserID#", "department", JavaCast("string", "#strDept#"))>
					<cfif lngResult EQ 0>
						<cfset lngResult = objMod.ModifyUser("#strUserID#", "physicalDeliveryOfficeName", JavaCast("string", "#strDept#"))>
						<cfif lngResult NEQ 0>
							<cfset strError=strError & " " & #objMod.GetErrorLog()#>
						</cfif>
					<cfelse>
						<cfset strError=strError & " " & #objMod.GetErrorLog()#>
					</cfif>
				<cfelse>
					<cfset strError=strError & " " & #objMod.GetErrorLog()#>
				</cfif>
				
			<cfelse>
				<cfset strError=strError & " " & #objMod.GetErrorLog()#>
				
			</cfif--->
			
			#strUserID# #strDesc# #strDept# <BR />
			
			<cfif strError EQ "">
				<!---#strUserID# - Successfully Updated--->
				<cfset intUpdated = intUpdated +1>
			<cfelse>
				#strUserID# - ERROR: #strError#
				<cfset intError = intError +1>
			</cfif>	
				
		<cfelse>
			#strUserID#	- SKIPPED
			<cfset intSkipped = intSkipped +1>
		</cfif>
		<BR />	
	</cfloop>
	
<BR />
Updated:  #intUpdated#<BR />
Skipped:  #intSkipped#<BR />
Errors:  #intError#
</cfmail>
</body>
</html>
